package com.itfreer.data.general.interceptor;

import com.itfreer.utils.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 定义数据拦截基类
 *
 */
public abstract class DbInterceptorClass implements IDbInterceptor {
	
	/**
	 * 所应用的表
	 */
	private List<String> tableNames;

	/**
	 * 拦截名
	 * 
	 * @return
	 */
	public abstract String getInterceptorName();

	/**
	 * 注册适应表名称注册适应表名称
	 * @param tableName
	 */
	public void regTableName(String tableName) {
		if (tableNames == null)
			tableNames = new ArrayList<String>();
		if (StringUtils.IsNullOrSpace(tableName))
			return;
		tableName = tableName.toUpperCase().trim();
		if (!tableNames.contains(tableName))
			tableNames.add(tableName);
	}

	/**
	 * 移除适应表名称
	 * @param tableName
	 */
	public void removeTableName(String tableName) {
		if (tableNames == null)
			return;
		if (StringUtils.IsNullOrSpace(tableName))
			return;
		tableName = tableName.toUpperCase().trim();
		if (tableNames.contains(tableName)) {
			tableNames.remove(tableName);
		}
	}

	/**
	 * 是否包含列名称
	 * @param tableName
	 * @return
	 */
	public boolean contains(String tableName) {
		if (tableNames == null || tableNames.size() <= 0)
			return true;
		if (StringUtils.IsNullOrSpace(tableName))
			return false;
		tableName = tableName.toUpperCase().trim();
		return tableNames.contains(tableName);
	}

	/**
	 * 获取或设置拦截器索引
	 */
	private int index;

	/**
	 * 获取拦截器索引
	 */
	public final int getIndex() {
		return index;
	}

	/**
	 * 设置拦截器索引
	 */
	public final void setIndex(int value) {
		index = value;
	}
}
